package com.winit.openapi.wh.outbound.validator;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.winit.openapi.util.ValidateUtil;
/**
 * 
 * 商品信息校验器类
 * 
 * @version 
 * <pre>
 * Author	  Version		 Date		 Changes
 * dinghua.an 	   1.0  		2016年6月1日 	 Created
 *
 * </pre>
 * @since 1.
 */
public class OutboundOrderMerchandiseValidator {

    /**
     * 校验商品信息
     * @param json
     */
    public static void validUpdateMerchandise(JSONObject json) {
        //订单号
        ValidateUtil.isNotNull(json, "orderNo");
        ValidateUtil.validMaxLength(json, "orderNo", 64, true);
        //是否跨仓发货
        ValidateUtil.validMaxLength(json, "isAcrossWarehouse", 1, false);
        ValidateUtil.validByRegex(json, "isAcrossWarehouse", "[YN]");
        JSONArray array = json.getJSONArray("ebayInfoList");
        for (Object item : array) {
            JSONObject obj = (JSONObject) item;
            //商品ID
            ValidateUtil.isNotNull(obj, "merchandiseId");
            ValidateUtil.validMaxLength(obj, "merchandiseId", 20, true);
            //ebayTransactionId
            ValidateUtil.validMaxLength(obj, "ebayTransactionId", 64, false);
            //ebayItemId
            ValidateUtil.validMaxLength(obj, "ebayItemId", 64, false);
            //出库数量
            ValidateUtil.validInteger(obj, "qty", "qty", true);
        }
    }
}
